package com.learning.cloud2020.controller;

import com.learning.cloud2020.client.PaymentFeignClient;
import com.learning.cloud2020.entities.Payment;
import com.learning.cloud2020.model.CommonResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/feign")
public class ConsumerController {

    private final PaymentFeignClient paymentFeignClient;

    public ConsumerController(PaymentFeignClient paymentFeignClient) {
        this.paymentFeignClient = paymentFeignClient;
    }

    @PostMapping("/payment/create")
    public CommonResult create(Payment payment) {
        return paymentFeignClient.create(payment);
    }

    @GetMapping("/payment/{id}")
    CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        return paymentFeignClient.getPaymentById(id);
    }

    @GetMapping("/payment/timeout/{sleepMillis}")
    public CommonResult<Payment> getPaymentByIdTimeOut(@PathVariable("sleepMillis") Long sleepMillis) {
        return paymentFeignClient.getPaymentByIdTimeOut(sleepMillis);
    }

    @GetMapping("/payment/discovery")
    Object discovery() {
        return paymentFeignClient.discovery();
    }

}
